home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / resource / earshot / eardemo.dir / 00406_styled text printing scripts.ls < prev    next >
Encoding:
Text File  |  1996-05-17  |  2.7 KB  |  88 lines

  1. on PrintStyledText castList
  2.   if not listp(castList) then
  3.     exit
  4.   end if
  5.   if the machineType = 256 then
  6.     set XObjFile to "pmatic.dll"
  7.   else
  8.     set XObjFile to "pmatic.xobj"
  9.   end if
  10.   openXLib(XObjFile)
  11.   set printer to PrintOMatic(mnew)
  12.   if not objectp(printer) then
  13.     alert("There is no currently selected printer. Printing features are disabled.")
  14.   else
  15.     printer(mSetMargins, 72, 72, 72, 72)
  16.     set w to printer(mGetPageWidth)
  17.     set h to printer(mgetpageheight)
  18.     printer(mNewPage)
  19.     printer(mTextBox, 0, 0, w, h, 0)
  20.     repeat with cnt = 1 to count(castList)
  21.       AppendStyledText(printer, getAt(castList, cnt), 1)
  22.     end repeat
  23.     if printer(mDoJobSetup) = 1 then
  24.       updateStage()
  25.       printer(mPrintPreview)
  26.     end if
  27.     printer(mdispose)
  28.   end if
  29.   closeXLib(XObjFile)
  30. end
  31.  
  32. on AppendStyledText obj, theCast, autoAppend
  33.   if not objectp(obj) then
  34.     exit
  35.   end if
  36.   if not integerp(theCast) and not stringp(theCast) then
  37.     exit
  38.   end if
  39.   if the castType of cast theCast <> #text then
  40.     exit
  41.   end if
  42.   if not (the number of chars in field theCast) then
  43.     exit
  44.   end if
  45.   if not integerp(autoAppend) then
  46.     set autoAppend to 0
  47.   end if
  48.   set styleList to BuildStyleList(theCast)
  49.   repeat with cnt = 1 to count(styleList)
  50.     set styleRun to getAt(styleList, cnt)
  51.     obj(mSetTextFont, getaProp(styleRun, #font))
  52.     obj(mSetTextSize, getaProp(styleRun, #size))
  53.     obj(mSetTextStyle, getaProp(styleRun, #style))
  54.     set charsAdded to obj(mAppendText, char getaProp(styleRun, #start) to getaProp(styleRun, #end) of field theCast, autoAppend)
  55.     if charsAdded = 0 then
  56.       exit
  57.     end if
  58.   end repeat
  59. end
  60.  
  61. on BuildStyleList theCast
  62.   if the castType of cast theCast <> #text then
  63.     return []
  64.   end if
  65.   if not (the number of chars in field theCast) then
  66.     return []
  67.   end if
  68.   set styleList to []
  69.   set curFont to EMPTY
  70.   set curSize to 0
  71.   set curStyle to EMPTY
  72.   repeat with cnt = 1 to the number of chars in field theCast
  73.     if (the textFont of char cnt of cast theCast <> curFont) or (the textSize of char cnt of cast theCast <> curSize) or (the textStyle of char cnt of cast theCast <> curStyle) then
  74.       if count(styleList) then
  75.         setaProp(getAt(styleList, count(styleList)), #end, cnt - 1)
  76.       end if
  77.       set curFont to the textFont of char cnt of cast theCast
  78.       set curSize to the textSize of char cnt of cast theCast
  79.       set curStyle to the textStyle of char cnt of cast theCast
  80.       add(styleList, [#font: curFont, #size: curSize, #style: curStyle, #start: cnt, #end: cnt])
  81.     end if
  82.   end repeat
  83.   if count(styleList) then
  84.     setaProp(getAt(styleList, count(styleList)), #end, the number of chars in field theCast)
  85.   end if
  86.   return styleList
  87. end
  88.